/**
 * @param {string[]} words
 * @return {number}
 */
// 按字母进行转换，然后拼接，最后看一共有多少种不同的组合
// 转换之后去重，然后 count 应该可以满足要求
var uniqueMorseRepresentations = function (words) {
    let morses = words.map(word => {
        return char2morse(word).join('')
    })
    let x = morses.filter(onlyUnique)
    return x.length
};

function onlyUnique(value, index, self) {
    return self.indexOf(value) === index;
};

function char2morse(word) {
    let code = [".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."]
    if (word === '') {
        return ''
    } else {
        let chars = word.split('')
        let charsMorseRelIndex = chars.map(char => {
            return char.charCodeAt() - 97
        }).map(index => {
            return code[index]
        })
        return charsMorseRelIndex
    }
}

console.dir(uniqueMorseRepresentations(["gin", "zen", "gig", "msg"]))
